package com.books.mapper.common;

import com.books.model.entity.backcontroller.Chat;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author 饿熊的咆哮
 * @Date 2021/10/1 15:08
 * @Version 1.0
 */
@Mapper
public interface ChatMapper {
    //根据接收者id查询chat
    @Select("select * from chat where take_people_id=#{takePeopleId}")
    List<Chat> findByTake(Integer takePeopleId);

    @Select("select * from chat where (take_people_id=#{adminPeopleId} and send_people_id=#{userPeopleId}) or (take_people_id=#{userPeopleId} and send_people_id=#{adminPeopleId}) order by chat_id desc")
    List<Chat> findHistoryChat(Integer adminPeopleId,Integer userPeopleId);

    //查询当前接收者的已读未读
    @Select("select * from chat where take_people_id=#{takePeopleId} and if_read=#{ifRead} order by chat_id desc")
    List<Chat> findRead(Integer takePeopleId,boolean ifRead);

    @Insert("insert into chat values(null,#{sendPeopleId},#{takePeopleId},#{sendTime},#{chat},#{ifRead})")
    void addChat(Chat chat);

    @Delete("delete from chat where send_people_id=#{peopleId} or take_people_id=#{peopleId}")
    void delChat(Integer peopleId);

    @Update("update chat set if_read=#{ifRead} where chat_id=#{chatId}")
    void updateChat(boolean ifRead,Integer chatId);

}
